$(function () {
    $('#header').eq(0).click(function () {
        location.href = '../index.html'
    })
    let backPage = document.querySelector('.subNav>a:nth-of-type(2)')
    let ownPage = document.querySelector('.subNav>a:nth-of-type(3)')
    let title = getQueryString('title')
    let productid = getQueryString('productid')
    let categoryid = getQueryString('categoryid')
    let main = document.querySelector('#main')
    let comContainer = document.querySelector('.comment>.comContainer')
    fetch('http://chst.vip:1234/api/getproduct?productid=' + productid)
        .then(body => body.json())
        .then(res => {
            console.log(res)
            ownPage.innerHTML = res.result[0].productName
            ownPage.onclick = function () {
                location.reload()
            }
            let str = ''
            let regExp = /(\/|http)[^>]+\.(jpg|jpeg|png|gif)/g;
            src = res.result[0].productImg.match(regExp)
            src = src ? src[0] : res.result[0].productImg
            str = `<div class="show">
        <div class="pic">
            <img src=${src} alt="">
        </div>
        <div class="title">
        ${res.result[0].productName}
        </div>
        <div class="count">
        <span>当前最低 ￥6000</span><span>优选评论 8266条</span>
        </div>
    </div>
    <div class="buy">
        ${res.result[0].bjShop}
    </div>`
            main.innerHTML = str
            fetch("http://chst.vip:1234/api/getproductcom?productid=" + productid)
                .then(body => body.json())
                .then(res => {
                    console.log(res)
                    let str = ''
                    res.result.forEach(item => {
                        str += `<div class='container'><div>
        <span>
            ${item.comName}
        </span>
        <span>
            ${item.comTime}
        </span>
    </div>
    <p>${item.comContent}</p>
    <div>
        <p>${item.comFrom}</p>
        </div>
        </div>`
                    })
                    comContainer.innerHTML = str
                })
        })
    fetch('http://chst.vip:1234/api/getcategorybyid?categoryid=' + categoryid)
        .then(body => body.json())
        .then(res => {
            backPage.innerHTML = res.result[0].category + '>'
            backPage.onclick = function () {
                location.href = './bjsearchList.html?categoryid=' + categoryid + '&title=' + title
            }
        })

})